<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            <select id="commodity_type" name="commodity_type" class="layui-input" lay-filter="commodity_type" style="width: 150px;">
                <option value="">商品类型</option>
                <option value="0">虚拟商品</option>
                <option value="1">实物商品</option>
            </select>
        </div>
        <div class="layui-inline">
            <select id="commodity_classification" name="commodity_classification" class="layui-input"lay-filter="commodity_classification" style="width: 120px;">
                <option value="">商品分类</option>
                <?php foreach($cate as $key=>$value):?>
                <option value="<?php echo $key;?>"><?php echo $value;?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="commodity_name" id="commodity_name" placeholder="商品名称" class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="valid_start_time" placeholder="开始时间">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="valid_end_time" placeholder="结束时间">
        </div>
        <div class="layui-inline">
            <select id="is_use" name="is_use" class="layui-input"lay-filter="is_use" style="width: 120px;">
                <option value="">状态</option>
                <option value="1">已上架</option>
                <option value="0">已下架</option>
            </select>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="search">搜索</button>
            <button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this,'添加商品')">
                添加商品
            </button>
        </div>
    </blockquote>

    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Point/index')}', page: true, limit: 10, id:'test'}" lay-filter="test">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'commodity_id', width:100,align:'center', fixed: true, sort: true}">商品ID</th>
            <th lay-data="{field:'commodity_type', width:100,align:'center'}">商品类型</th>
            <th lay-data="{field:'classification_name', width:100,align:'center'}">商品分类</th>
            <th lay-data="{field:'commodity_name', width:300,align:'center'}">商品名称</th>
            <th lay-data="{field:'valid_start_time', width:180,align:'center'}">兑换开始时间</th>
            <th lay-data="{field:'valid_end_time', width:180,align:'center'}">兑换结束时间</th>
            <th lay-data="{field:'need_integral', width:100,align:'center'}">兑换积分</th>
            <th lay-data="{field:'number', width:100,align:'center'}">总库存</th>
            <th lay-data="{field:'has_change_number', width:100,align:'center'}">已兑换</th>
            <th lay-data="{field:'is_use_str', width:100,align:'center'}">状态</th>
            <th lay-data="{field:'admin_name', width:100,align:'center'}">添加人</th>
            <th lay-data="{field:'add_time', width:180,align:'center'}">添加时间</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:300, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="width: 50px">删除</a>

        {{#if(d.is_use == 1){}}
        <a class="layui-btn layui-btn-xs layui-btn-disabled" style="width: 50px">上架</a>
        <a class="layui-btn layui-btn-xs " lay-event="is_use_down" style="width: 50px">下架</a>
        {{#}else{}}
        <a class="layui-btn layui-btn-xs " lay-event="is_use_up" style="width: 50px">上架</a>
        <a class="layui-btn layui-btn-xs layui-btn-disabled" style="width: 50px">下架</a>
        {{#}}}

    </script>
    <script>
        layui.use(['form','table','laydate'], function () {
            var table = layui.table,form = layui.form,laydate = layui.laydate;
            laydate.render({
                elem: '#valid_start_time' //指定元素
            });
            laydate.render({
                elem: '#valid_end_time' //指定元素
            });
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var commodity_id = data.commodity_id;

                if (obj.event === 'del') {
                    layer.confirm('确定删除吗?',function(index){
                        var url = '{:url("/admin/Point/del","commodity_id=")}' + commodity_id
                        $.get(url,function(data){
                            if(data.status == 1){
                                layer.msg('成功删除',{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg('操作失败',{'icon':2});
                            }
                        },'json')
                        layer.close(index);
                    })
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '商品分类修改',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/Point/edit","commodity_id=")}' + commodity_id //iframe的url
                    });

                } else if (obj.event === 'is_use_up') {
                    layer.confirm('确定上架吗?',function(index){
                        var url = '{:url("/admin/Point/is_use","is_use=1&commodity_id=")}' + commodity_id
                        $.get(url,function(data){
                            if(data.status == 1){
                                layer.msg('成功删除',{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg('操作失败',{'icon':2});
                            }
                        },'json')
                        layer.close(index);
                    })

                } else if (obj.event === 'is_use_down') {
                    layer.confirm('确定下架吗?',function(index){
                        var url = '{:url("/admin/Point/is_use","is_use=0&commodity_id=")}' + commodity_id
                        $.get(url,function(data){
                            if(data.status == 1){
                                layer.msg('成功删除',{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg('操作失败',{'icon':2});
                            }
                        },'json')
                        layer.close(index);
                    })

                }

            });
            //搜索
            $('.layui-btn').on('click', function () {
                var commodity_type = $("#commodity_type").val();
                var commodity_classification = $("#commodity_classification").val();
                var commodity_name = $("#commodity_name").val();
                var valid_start_time = $("#valid_start_time").val();
                var valid_end_time = $("#valid_end_time").val();
                var is_use = $("#is_use").val();
                table.reload('test', {
                    url: '/admin/Point/index', where: {
                        "commodity_type": commodity_type,
                        "commodity_classification": commodity_classification,
                        "commodity_name": commodity_name,
                        "valid_start_time": valid_start_time,
                        "valid_end_time": valid_end_time,
                        "is_use": is_use
                    }
                });
            })
        });

    </script>
</block>
